package com.powernode.queryops;

import com.powernode.commons.util.DbUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @Author Arrebol
 * @Date 2024/8/1 15:02
 * @Project jdbc
 * @Description： 测试DbUtils工具类
 */
public class JdbcTest5 {
    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            conn = DbUtils.getConnection();
            stmt = conn.createStatement();
            String sql1 = "insert into t_product (name, price, create_time) " +
                    "values ('小米su7',1.0,'2024/08/01')";
            int count = stmt.executeUpdate(sql1, Statement.RETURN_GENERATED_KEYS);
            System.out.println("插入了" + count + "条记录");
            rs = stmt.getGeneratedKeys();
            if (rs.next()) {
                long id = rs.getLong(1);
                System.out.println("新增行的主键值为：" + id);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DbUtils.close(rs, stmt, conn);
        }
    }
}
